package com.qk.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qk.common.PageResult;
import com.qk.entity.Course;
import com.qk.mapper.CourseMapper;
import com.qk.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class CourseServiceImpl implements CourseService {

    @Autowired
    private CourseMapper courseMapper;

    @Override
    public PageResult<Course> getPageList(Integer subject,String name,Integer target, Integer page, Integer pageSize) {
        PageHelper.startPage(page,pageSize);
        List<Course> courseList = courseMapper.courseSelectByCondition(subject,name,target);
        PageInfo<Course> pageInfo = new PageInfo<>(courseList);
        return new PageResult<>(pageInfo.getTotal(),pageInfo.getList());
    }


    @Override
    public void CourseDelete(Integer id) {
        courseMapper.deleteById(id);
    }

    @Override
    public void addCourse(Course course) {
        course.setCreateTime(LocalDateTime.now());
        course.setUpdateTime(LocalDateTime.now());
        courseMapper.insert(course);
    }


    @Override
    public Course findCourseById(Integer id) {
        return courseMapper.search(id);
    }

    @Override
    public void updateCourse(Course course) {
        course.setUpdateTime(LocalDateTime.now());
        courseMapper.courseUpdate(course);
    }

    @Override
    public List<Course> getCourseList(Course course) {
        return courseMapper.allCourselist(course);
    }

    @Override
    public List<Course> getCourseBySubject(Integer subject) {
        return courseMapper.findCourseBySubject(subject);
    }
}
